package cn.jiedanba.itext5.gm.sign.timestamp;

import com.itextpdf.text.pdf.security.TSAClient;
import org.ofdrw.sign.timestamp.TimeStampHook;

/**
 * 国密时间戳签名
 */
public class GMTimeStampHook implements TimeStampHook {

    private final TSAClient tsaClient;

    public GMTimeStampHook(TSAClient tsaClient) {
        this.tsaClient = tsaClient;
    }

    @Override
    public byte[] apply(byte[] signature) {
        try {
            return tsaClient.getTimeStampToken(signature);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("时间戳签名异常", e);
        }
    }

}
